package com.itheima.reggie.controller;

import com.itheima.reggie.commom.ResultInfo;
import com.itheima.reggie.domain.User;
import com.itheima.reggie.dto.LoginDto;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Sea
 * @date 2023/3/8 17:20
 */
@RestController
public class UserController {
@Autowired
    private UserService userService;
//发送短信
    @PostMapping("/user/sendMsg")
    public ResultInfo sendMsg(@RequestBody User user){
        //接收参数
        userService.sendMsg(user.getPhone());
        //发送短信成功
        return  ResultInfo.success();
    }
    //登录注册
    @PostMapping("/user/login")
    public ResultInfo login(@RequestBody LoginDto loginDto){
        String token = userService.login(loginDto.getPhone(), loginDto.getCode());
        //返回结果
        return  ResultInfo.success(token);
    }
    //退出
    // 用户退出
    @PostMapping("/user/logout")
    public ResultInfo logout(){
        return ResultInfo.success();
    }
}
